package top.wilsonlv.jaguar.commons.web.servlet;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;

import javax.servlet.http.HttpSessionListener;

/**
 * @author lvws
 * @since 2021/6/24
 */
@Configuration
public class ServletAutoConfiguration {

    @Bean
    public FilterRegistrationBean<JaguarRequestFilter> requestFilterRegistrationBean() {
        FilterRegistrationBean<JaguarRequestFilter> registration = new FilterRegistrationBean<>();
        registration.setFilter(new JaguarRequestFilter());
        registration.addUrlPatterns("/*");
        registration.setOrder(Ordered.HIGHEST_PRECEDENCE);
        return registration;
    }

    @Bean
    public HttpSessionListener httpSessionListener() {
        return new JaguarHttpSessionListener();
    }

}
